<template>
  <div class="hotsift" v-if="contentData.list||contentData.children" ref="find">
    <div v-if="ids == 1">
      <van-nav-bar fixed style="z-index:99">
        <template #left>
          <i
            class="iconfont icon-fanhui"
            style="font-size: 20px; font-weight: 600"
            @click="$router.back()"
          ></i>
        </template>
        <template #title>
          <span style="font-size: 18px; font-weight: 600">分类热门</span>
        </template>
      </van-nav-bar>
      <div class="selectorbox" v-if="screenShow">
      <div class="selector" v-if="contentData.header">
        <div class="item" :class="{active:indexs==0}" @click="selectitem($event,0, 0)">
          <p>全部</p>
        </div>
        <div
          class="item"
          :class="{active:indexs==index+1}"
          @click="selectitem($event, i.value,index+1)"
          v-for="(i, index) in contentData.header.categories"
          :key="index"
        >
          <p>{{ i.title }}</p>
        </div>
        <div class="btn">
          <i @click="screenShow = false" class="iconfont icon-fenlei"></i>
        </div>
      </div>
    </div>
    <transition
      name="fade"
      enter-active-class="animated fadeInDown"
      leave-active-class="animated fadeOutUp"
    >
      <div class="screen" v-if="!screenShow">
        <div class="head">
          <span>筛选</span>
          <i @click="screenShow = true" class="iconfont icon-shanchu"></i>
        </div>
        <div class="body" v-if="contentData.header">
          <div class="item" :class="{active:indexs==0}" @click="selectitem($event,0, 0)">
            <p>全部</p>
          </div>
          <div
            class="item"
            :class="{active:indexs==index+1}"
            @click="selectitem($event, i.value,index+1)"
            v-for="(i, index) in contentData.header.categories"
            :key="index"
          >
            <p>{{i.title }}</p>
          </div>
        </div>
      </div></transition>
      <div class="cardbox">
      <FinddeItem v-if="!load" :list="contentData.list"></FinddeItem>
      <MyLoading class="lll" v-if="load"></MyLoading>
    </div>
    </div>
    <div v-if="ids == 2">
      <van-nav-bar fixed style="z-index:99">
        <template #left>
          <i
            class="iconfont icon-fanhui"
            style="font-size: 20px; font-weight: 600"
            @click="$router.back()"
          ></i>
        </template>
        <template #title>
          <span style="font-size: 18px; font-weight: 600">分类精选</span>
        </template>
      </van-nav-bar>
      <div class="selectorbox" v-if="screenShow">
      <div class="selector" v-if="contentData.header">
        <div :class="{active:indexs==0}" class="item" @click="selectitem($event, 0,0)">
          <p>全部</p>
        </div>
        <div
          class="item"
          :class="{active:indexs==index+1}"
          @click="selectitem($event, i.value,index+1)"
          v-for="(i, index) in contentData.header.categories"
          :key="index"
        >
          <p>{{ i.title }}</p>
        </div>
        <div class="btn">
          <i @click="screenShow = false" class="iconfont icon-fenlei"></i>
        </div>
      </div>
    </div>
    <transition
      name="fade"
      enter-active-class="animated fadeInDown"
      leave-active-class="animated fadeOutUp"
    >
      <div class="screen" v-if="!screenShow">
        <div class="head">
          <span>筛选</span>
          <i @click="screenShow = true" class="iconfont icon-shanchu"></i>
        </div>
        <div class="body" v-if="contentData.header">
          <div class="item" :class="{active:indexs==0}" @click="selectitem($event, 0,0)">
            <p>全部</p>
          </div>
          <div
            class="item"
            :class="{active:indexs==index+1}"
            @click="selectitem($event, i.value,index+1)"
            v-for="(i, index) in contentData.header.categories"
            :key="index"
          >
            <p>{{i.title }}</p>
          </div>
        </div>
      </div></transition>
      <div class="cardbox">
      <FinddeItem v-if="!load" :list="contentData.list"></FinddeItem>
      <MyLoading class="lll" v-if="load"></MyLoading>
    </div>
    </div>
    <div v-if="ids == 3">
        <van-nav-bar fixed style="z-index:99">
        <template #left>
          <i
            class="iconfont icon-fanhui"
            style="font-size: 20px; font-weight: 600"
            @click="$router.back()"
          ></i>
        </template>
        <template #title>
          <span style="font-size: 18px; font-weight: 600">场库精选</span>
        </template>
      </van-nav-bar>
        <div class="bigbox">
            <div class="item" v-for="(item,index) in contentData.children" :key="index">
            <uiBigCard :item="item"></uiBigCard>
        </div>
        </div>
    </div>
  </div>
  <MyLoading class="lll" v-else></MyLoading>
</template>

<script>
import Vue from "vue";
import { NavBar } from "vant";
import FinddeItem from "@/components/FinddeItem.vue";
import uiBigCard from "@/components/uiBigCard.vue";
import MyLoading from "@/components/MyLoading.vue";
Vue.use(NavBar);
export default {
  data() {
    return {
      contentData: {},
      ids: this.$route.query.id,
      screenShow: true,
      load:false,
      indexs:0,
    };
  },
  components: {
    FinddeItem,
    uiBigCard,
    MyLoading
  },
  methods:{
      selectitem(e, id,index) {
        this.screenShow = true
        this.load=true;
        this.indexs=index;
        console.log(index);
      let url = ''
      if(this.ids ==1){
          url="https://apis.netstart.cn/xpc/home/cateHot?category_id=" + id
      }else if(this.ids==2){
          url = 'https://apis.netstart.cn/xpc/home/cateSelection?type='+id
      } 
      this.axios
        .get(url)
        .then((res) => {
          this.contentData = res.data.data;
          setTimeout(()=>{
          this.load=false
          },500)
        });
      this.$refs.find.querySelectorAll(".item").forEach((e) => {
        if (e.classList.contains("active")) {
          e.classList.remove("active");
        }
      });
      e.target.parentNode.classList.add("active")
    },
  },
  created() {
    if (this.ids == 1) {
      this.axios
        .get("https://apis.netstart.cn/xpc/home/cateHot")
        .then((res) => {
          this.contentData = res.data.data;
        });
    } else if (this.ids == 2) {
      this.axios
        .get("https://apis.netstart.cn/xpc/home/cateSelection")
        .then((res) => {
          this.contentData = res.data.data;
          // console.log(res);
        });
    } else if (this.ids == 3) {
      this.axios
        .get("https://apis.netstart.cn/xpc/home/vmovier")
        .then((res) => {
          this.contentData = res.data.data;
          // console.log(res);
        });
    }
  },
};
</script>

<style lang="less" scoped>
.hotsift{
    background-color: #f7f7f7;
}
.lll{
  width: 100% !important;

}
.selectorbox {
    width: 100%;
    position: fixed;
    top: 45px;
    left: 0;
    z-index: 10;
    .selector {
      width: 100%;
      height: 50px;
      display: flex;
      align-items: center;
      padding-left: 20px;
      background-color: #fff;
      padding-right: 56px;
      flex-wrap: nowrap;
      overflow-x: scroll;
      border-bottom: 1px solid #f7f7f7;
      &::-webkit-scrollbar {
        display: none;
      }
      .btn {
        width: 70px;
        height: 50px;
        background-image: linear-gradient(to right, transparent 0%, white 20%);
        position: absolute;
        right: 0;
        display: flex;
        justify-content: center;
        align-items: center;
        i {
          font-size: 26px;
        }
      }
      .item {
        flex: 1;
        font-size: 12px;
        p {
          padding: 7px 15px;
          white-space: nowrap;
          margin-right: 10px;
          border-radius: 4px;
          background-color: #efefef;
          color: #aaa;
        }
        &.active {
          p {
            color: rgb(231, 78, 78);
          }
        }
      }
    }
  }
  .screen {
    width: 100vw;
    height: 200vw;
    position: fixed;
    top: 46px;
    left: 0;
    z-index: 10;
    background-color: rgba(0, 0, 0, 0.4);
    .head {
      height: 50px;
      display: flex;
      align-items: center;
      padding: 0 20px;
      background-color: #fff;
      justify-content: space-between;
      color: #444;
      border-bottom: 1px solid #f7f7f7;
      span {
        font-size: 15px;
        font-weight: 600;
      }
      i {
        font-weight: 600;
      }
    }
    .body {
      padding: 20px;
      display: flex;
      flex-wrap: wrap;
      width: 100vw;
      justify-content: flex-start;
      background-color: #fff;
      .item {
        font-size: 12px;
        margin-bottom: 10px;
        p {
          display: inline-block;
          padding: 7px 15px;
          white-space: nowrap;
          margin-right: 10px;
          border-radius: 4px;
          background-color: #efefef;
          color: #aaa;
        }
        &.active {
          p {
            color: rgb(231, 78, 78);
          }
        }
      }
    }
  }
  .animated {
    animation-duration: 0.3s;
  }
  .cardbox {
    // width: 100%;
    padding: 0 20px;
    margin-top: 100px;
    background-color: #fff;
  }
  .bigbox{
      padding: 0 15px;
      padding-top: 60px;
      .item{
          margin-bottom: 10px;
      }
  }
</style>